package com.example.arithmeticleetcode.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description: 1431. 拥有最多糖果的孩子
 * @author: FangZhen
 * @create: 2020-05-08 14:21
 **/
public class Demo14 {

    public static void main(String[] args) {
        int[] candies1 = {2, 3, 5, 1, 3}; // [true,true,true,false,true]
        int[] candies2 = {4, 2, 1, 1, 2};// [true,false,false,false,false]
        int[] candies3 = {12, 1, 12};//[true,false,true]
        System.out.println(kidsWithCandies(candies1, 3));
        System.out.println(kidsWithCandies(candies2, 1));
        System.out.println(kidsWithCandies(candies3, 10));
    }

    public static List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
        int max = -1;
        for (int candy : candies) {
            if (candy > max) {
                max = candy;
            }
        }

        List<Boolean> list = new ArrayList<>(candies.length);
        for (int candy : candies) {
            if (candy + extraCandies >= max) {
                list.add(true);
            } else {
                list.add(false);
            }
        }
        return list;
    }
}
